<?php defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

/* JoomLeague League Management and Prediction Game for Joomla!
 * @version $Id: edit_match_events.tpl.php 1151 2008-06-24 15:07:32Z julienv $
 * @package Joomleague
 * @copyright Copyright (C) 2007  JoomLeague
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see _joomleague_license.txt
 *  
 * Homepage: http://www.joomleague.de
 * Support: htt://www.joomleague.de/forum/
 * 
 * This file is part of JoomLeague.
 *  
 * JoomLeague is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * Please note that the GPL states that any headers in files and
 * Copyright notices as well as credits in headers, source files
 * and output (screens, prints, etc.) can not be removed.
 * You can extend them with your own credits, though...
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * The "GNU General Public License" (GPL) is available at
 * http://www.gnu.org/copyleft/gpl.html.
*/ 

function printTeamEventsForms( $teamevents, $eventtypes, $playeroptions, $events_required=0 )
{
  static $counter = 1;
  
	if ( count($teamevents) == 0 ) return; 

  foreach( $teamevents as $event )
  {
    $thiseventid = $event->event_id;
    
    if ($eventtypes[$event->event_type_id]->double==1) $display_player2='inline'; else $display_player2='none';
    ?>
    <form id="eventForm<?php echo $thiseventid;?>" name="eventForm<?php echo $thiseventid;?>" 
          action="javascript: jl_PostForm( serializeLineupForm(document.getElementById('eventForm<?php echo $thiseventid;?>')), 'editarea' );"
          enctype="application/x-www-form-urlencoded">
    <input type="hidden" id="mytask<?php echo $counter;?>" name="mytask" value="" />
    <input type="hidden" name="mid" value="<?php echo $event->match_id;?>" />
    <input type="hidden" name="func" value="editEvents" />
    <input type="hidden" name="act" value="editEvents" />
    <input type="hidden" name="p" value="<?php echo $event->project_id;?>" />
    <input type="hidden" name="option" value="com_joomleague" />
    <input type="hidden" name="no_html" value="1" />
    <input type="hidden" name="event_player_double" id="event_player_double<?php echo $counter; ?>" value="<?php echo $eventtypes[$event->event_type_id]->double; ?>" />
    <input type="hidden" name="event_notice" id="event_notice<?php echo $counter; ?>" value="<?php echo $eventtypes[$event->event_type_id]->splitt; ?>" />
    
    <select name="event_type_id" id="event_type_id<?php echo $counter; ?>" 
                  class="inputbox" style="font-size:9px" 
                  onclick="SplitName = this.options[this.selectedIndex].title.split('-');
                     document.getElementById('event_player_double<?php echo $counter; ?>').value = SplitName[0];
                     document.getElementById('event_notice<?php echo $counter; ?>').value = SplitName[1];
                     if (getElementById('event_player_double<?php echo $counter; ?>').value==1) {
                      document.getElementById('showhometeam2<?php echo $counter; ?>').style.display='inline';
                     } 
                     else {
                      document.getElementById('showhometeam2<?php echo $counter; ?>').style.display='none';
                     }
                     <?php if ($events_required) { ?>
    				 if (((document.getElementById('event_player_double<?php echo $counter; ?>').value == 1 && document.getElementById('player_id2_<?php echo $counter; ?>').value != 0)
                                 || (document.getElementById('event_player_double<?php echo $counter; ?>').value == 0 && document.getElementById('player_id_<?php echo $counter; ?>').value != 0))
                       && ((document.getElementById('event_notice<?php echo $counter; ?>').value == 1 && document.getElementById('notice<?php echo $counter; ?>').value != '')
                                 || (document.getElementById('event_notice<?php echo $counter; ?>').value == 0))
                       && document.getElementById('event_type_id<?php echo $counter; ?>').value != 0
                       && document.getElementById('event_sum<?php echo $counter; ?>').value > 0) 
                     {
						document.getElementById('submitter<?php echo $counter; ?>').disabled=false;
					 } else document.getElementById('submitter<?php echo $counter; ?>').disabled=true;<?php } ?>">    
      <?php
      foreach ($eventtypes AS $type) 
      {
        echo '<option value="'.$type->id.'" title="'.$type->double.'-'.$type->splitt.'"';
        if ($type->id == $event->event_type_id) echo ' selected="selected"';
        echo '>'.jl_utf8_convert($type->name).'</option>';
      }
      ?>
    </select>
    <br />
    <select name="player_id" id="player_id_<?php echo $counter; ?>" class="inputbox"<?php echo ($events_required) ? ' onchange="if ( this.selectedIndex!=0 ) {
                                               if (((document.getElementById(\'event_player_double'.$counter.'\').value == 1 && document.getElementById(\'player_id2_'.$counter.'\').value != 0)
                                                          || (document.getElementById(\'event_player_double'.$counter.'\').value == 0))
                                               && ((document.getElementById(\'event_notice'.$counter.'\').value == 1 && document.getElementById(\'notice'.$counter.'\').value != \'\')
                                                          || (document.getElementById(\'event_notice'.$counter.'\').value == 0))
                                               && document.getElementById(\'event_type_id'.$counter.'\').value != 0
                                               && document.getElementById(\'event_sum'.$counter.'\').value > 0) {
												document.getElementById(\'submitter'.$counter.'\').disabled=false;
											   }
											}
											else document.getElementById(\'submitter'.$counter.'\').disabled=true;' : ''; ?>">
    <?php 
    foreach ( $playeroptions AS $player_id => $player) 
    {
      echo '<option value="'.$player_id.'"';
      if ( $player_id == $event->player_id ) echo ' selected="selected"';
      echo '>'.$player.'</option>';
    }
    ?>
    </select>
    <div id="showhometeam2<?php echo $counter; ?>" style="display:<?php echo $display_player2; ?>">
      <br />
      <select name="player_id2" id="player_id2_<?php echo $counter; ?>" class="inputbox"<?php echo ($events_required) ? ' onchange="if ( this.selectedIndex!=0 ) {
    										if (document.getElementById(\'player_id_'.$counter.'\').value != 0 && document.getElementById(\'event_sum'.$counter.'\').value > 0
                                               && ((document.getElementById(\'event_notice'.$counter.'\').value == 1 && document.getElementById(\'notice'.$counter.'\').value != \'\')
                                                          || (document.getElementById(\'event_notice'.$counter.'\').value == 0))) {
												document.getElementById(\'submitter'.$counter.'\').disabled=false;
											}
    									} else document.getElementById(\'submitter'.$counter.'\').disabled=true;"' : ''; ?>>
      <?php 
      foreach ( $playeroptions AS $player_id => $player ) 
      {
        echo '<option value="'.$player_id.'"';
        if ($player_id == $event->player_id2) echo ' selected="selected"';
        echo '>'.$player.'</option>';
      }
      ?>
      </select>
    </div>
    <?php echo _JL_ADMIN_EDIT_FORM_MATCHEVENTS_MINUTE;?>
    <input type="text" size="3" name="event_time" id="event_time" 
           value="<?php echo $event->event_time;?>" 
           class="inputbox" style="font-size:9px" />
    
    <?php echo _JL_ADMIN_EDIT_FORM_MATCHEVENTS_SUM;?>
    <input type="text" size="3" name="event_sum" id="event_sum<?php echo $counter; ?>" 
           value="<?php echo $event->event_sum;?>" 
           class="inputbox" style="font-size:9px"<?php echo ($events_required) ? ' onkeyup="if (((document.getElementById(\'event_player_double'.$counter.'\').value == 1 && document.getElementById(\'player_id2_'.$counter.'\').value != 0)
                                 || (document.getElementById(\'event_player_double'.$counter.'\').value == 0 && document.getElementById(\'player_id_'.$counter.'\').value != 0))
                       && ((document.getElementById(\'event_notice'.$counter.'\').value == 1 && document.getElementById(\'notice'.$counter.'\').value != \'\')
                                 || (document.getElementById(\'event_notice'.$counter.'\').value == 0))
                       && document.getElementById(\'event_type_id'.$counter.'\').value != 0
                       && document.getElementById(\'event_sum'.$counter.'\').value > 0) 
                     {
						document.getElementById(\'submitter'.$counter.'\').disabled=false;
					 } else document.getElementById(\'submitter'.$counter.'\').disabled=true;"' : ''; ?> />
    
    <?php echo _JL_ADMIN_EDIT_FORM_MATCHEVENTS_NOTICE;?>
    <input type="text" size="10" name="notice" id="notice<?php echo $counter; ?>" 
           value="<?php echo jl_utf8_convert($event->notice);?>" 
           class="inputbox" style="font-size:9px"<?php echo ($events_required) ? ' onkeyup="if (((document.getElementById(\'event_player_double'.$counter.'\').value == 1 && document.getElementById(\'player_id2_'.$counter.'\').value != 0)
                                 || (document.getElementById(\'event_player_double'.$counter.'\').value == 0 && document.getElementById(\'player_id_'.$counter.'\').value != 0))
                       && ((document.getElementById(\'event_notice'.$counter.'\').value == 1 && document.getElementById(\'notice'.$counter.'\').value != \'\')
                                 || (document.getElementById(\'event_notice'.$counter.'\').value == 0))
                       && document.getElementById(\'event_type_id'.$counter.'\').value != 0
                       && document.getElementById(\'event_sum'.$counter.'\').value > 0) 
                     {
						document.getElementById(\'submitter'.$counter.'\').disabled=false;
					 } else document.getElementById(\'submitter'.$counter.'\').disabled=true;"' : ''; ?> />
           
    <input type="submit" name="" value="<?php echo _JL_DELETE;?>" class="inputbox" style="font-size:9px" 
           onclick="document.getElementById('mytask<?php echo $counter;?>').value='deleteevent';" />
    <input type="submit" name="" id="submitter<?php echo $counter; ?>" value="<?php echo _JL_SAVE;?>" class="inputbox" style="font-size:9px" 
           onclick="document.getElementById('mytask<?php echo $counter;?>').value='updateevent';" />
    <input type="hidden" name="evid" id="evid" value="<?php echo $thiseventid;?>" />
    </form>
    <?php 
    $counter++;         
  }
}
?>

<div class="slider" id="slide_editEventsArea" style="display:<?php echo $display;?>" class="sectiontableentry1">
<?php
if (count($sortedevents) > 0) 
{
	?>
	<div align="left" style="margin-top:5px;"><a href="javascript:void(0);" onclick="document.getElementById('slide_editEventsArea').style.display='none';">close</a> 
	  <b><?php echo _JL_ADMIN_EDIT_FORM_MATCHEVENTS_TITLE._JL_ADMIN_EDIT_FORM_MATCHEVENTS_TITLE_EDIT;?>:</b>
	</div>
	
	<table style="border: thin;background-color:inherit;width:100%" cellspacing="0" cellpadding="2">
	 	<tr>
	   	<td style="width:50%;background-color:inherit;" valign="top">
			<?php
			foreach( $eventtypes AS $et ) 
			{
			  if ( isset( $sortedevents[$match->match_id][$et->id][$match->matchpart1]) ) {
			    $teamevents = $sortedevents[$match->match_id][$et->id][$match->matchpart1];  
			  }
			  else {
			    $teamevents = array();
			  }
			  
			  printTeamEventsForms( $teamevents, $eventtypes, $homeoptions, $events_required );
			}
			?>
			</td>
			<td style="width:50%;background-color:inherit;" valign="top">
				<?php
				foreach( $eventtypes AS $et ) 
				{
				  if ( isset( $sortedevents[$match->match_id][$et->id][$match->matchpart2]) ) {
				    $teamevents = $sortedevents[$match->match_id][$et->id][$match->matchpart2];  
				  }
				  else {
				    $teamevents = array();
				  }  
				  printTeamEventsForms( $teamevents, $eventtypes, $guestoptions, $events_required );
				}
				?>
	      </td>
		</tr>
	</table>
	<?php 
}
//else echo 'No Events for this Match yet!';
?>
</div>